﻿#!/usr/bin/env python
#coding:utf-8
#Code by Mango


from geColor import *
from geMulti import *
from os import path,system

class m:
    '''plugin's class 插件类'''
    def __init__(self,name): #初始化 传入 name = plugins/multi/scan_port_thread.py
        '''exec plugin code 管理插件代码'''
        fp   = open(name).read()    # 打开文件
        exec(fp)    # exec 执行储存在字符串或文件中的Python语句 
        code = '\n'
        for t in pygeplugin.opts:  # ['RHOST','127.0.0.1','Scan Target IP']
            o = t[0]
            v = t[1]
            code += 'global %s\n' % o  # global RHOST\n\n
            code += '%s="%s"\n' % (o,v)  #
        code += "global plugin\n"
        code += "plugin=pygeplugin()\n"
        exec(fp+code)
        '''
        global RHOST
        RHOST=127.0.0.1
        global plugin
        plugin=pygeplugin()
        '''

    def info(self):    # 显示插件信息
        color.cprint("PLUGIN INFOS",YELLOW)
        color.cprint("============",GREY)
        color.cprint("PARAMETER       VALUE",YELLOW)
        color.cprint("-"*15+" "+"-"*20,GREY)
        for n in plugin.infos:
            p = n[0]
            v = n[1]
            color.cprint("%-15s" % p,CYAN,0)
            color.cprint("%-s" % v,PURPLE)

    def opt(self):  # 显示插件可配置项
        color.cprint("PLUGIN OPTS",YELLOW)
        color.cprint("===========",GREY)
        color.cprint("%-15s %-20s %-40s"%("PARAMETER","VALUE","DESCRIPTION"),YELLOW)
        color.cprint("%-15s %-20s %-40s"%("-"*15,"-"*20,"-"*40),GREY)
        for n in plugin.opts:
            p=n[0]
            v=n[1]
            d=n[2]
            color.cprint("%-15s"%p,CYAN,0)
            exec('color.cprint("%-20s"%'+"%s"%p+',PURPLE,0)')
            color.cprint("%-40s"%d,GREEN)

    def setp(self, p, v):  # 设置插件的值 p,v = 传来的两个值
        p=p.upper()    # 转换为大写字母
        color.cprint("[*] SET %s=>%s"%(p,v),YELLOW)
        code  = 'global %s\n'%p
        code += '%s="%s"'%(p,v)
        exec(code)

    def run(self):    # 执行
        try:
            global fuck
            fuck=fuck()
        except:
            pass
        color.cprint("[*] Start ..",YELLOW)
        plugin.run()

    def printp(self,pt,plu):  # pt是类型,plu是xxx/xxx
        '''plugin color input 颜色输入插件'''
        ptmp = plu.split("/")
        pplu = plu[len(ptmp[0])+1:]  # 提取出xxx
        color.cprint("pyge",GREY,0)
        color.cprint("%s["%pt,WHITE,0)
        color.cprint(pplu,RED,0)
        color.cprint("]",WHITE,0)

    def pluhelp(self):
        '''plugin help menu 插件帮助目录'''
        color.cprint('PLUGIN HELP MENU',YELLOW)
        color.cprint('================',GREY)
        color.cprint('        Command         Description',YELLOW)
        color.cprint('        -------         -----------',GREY,0)
        color.cprint('''
        help            Displays the plugin menu
        back            Back to Mef Main
        cls             Clear the screen
        info            Displays the plugin info
        opts            Displays the mef options
        set             Configure the plugin parameters
        exploit         Start plugin to exploit''',CYAN)
        color.cprint('PLUGIN SET HELP',YELLOW)
        color.cprint('===============',GREY)
        color.cprint('        Command         Description',YELLOW)
        color.cprint('        -------         -----------',GREY,0)
        color.cprint('''
        PAYLOAD         Set payload
        <PARAMETER>     Set parameter''',CYAN)

    def cls(self):
        '''clear the screen 清除屏幕'''
        if  name == 'nt':
            system("cls")
        else:
            system("clear")

    def load(self):
        color.cprint("[?] USAGE::load <loadPlu>",YELLOW)

if __name__ == '__main__':
    print __doc__



